

function PrintPages(cp,tp,fId){
	this.currentPage = cp;
	this.totalPage = tp;
	this.formId = fId;
	this.getPrintHTML = function(){
		if(isNaN(this.totalPage)){
			return "<span style='color:red错误：总行数不是数字</span>";
		}
		if(isNaN(this.currentPage)){
			return "<span style='color:red错误：当前行数不是数字</span>";
		}
		if(this.totalPage < 1){
			return "<span style='color:red'>没有记录</span>";
		}
		if(this.currentPage<1) this.currentPage = 1;
		if(this.currentPage>this.totalPage) this.currentPage = this.totalPage;
		var prev_page_html = "";
		var next_page_html = "";
		var current_page_html = "<span class='current'>"+this.currentPage+"</span>";
		var dot_html = "...";
		if(this.currentPage<=1) prev_page_html="<span class='disabled'> < 上一页</span>";
		else prev_page_html="<a href='javascript:void(0);' onclick='gotoPage(\""+(this.currentPage-1)+"\",\""+this.formId+"\");return false;'> < 上一页</a>";
		
		if(this.currentPage==this.totalPage) next_page_html="<span class='disabled'> < 下一页</span>";
		else next_page_html="<a href='javascript:void(0);' onclick='gotoPage(\""+(this.currentPage+1)+"\",\""+this.formId+"\");return false;'>下一页 > </a>";
		var pages_html = "";
		var i = 1;
		if(this.totalPage<=12){
			for(i=1;i<=this.totalPage;i++){
				if(i == this.currentPage){
					pages_html+=current_page_html;
					continue;
				}
				pages_html+=this.getOtherPageHTML(i);
			}
		}else{
			if(this.currentPage<=5){
				for(i=1;i<=10;i++){
					if(i == this.currentPage){
						pages_html+=current_page_html;
						continue;
					}
					pages_html+=this.getOtherPageHTML(i);
				}
				pages_html+=dot_html;
				for(i=this.totalPage-1;i<=this.totalPage;i++){
					if(i == this.currentPage){
						pages_html+=current_page_html;
						continue;
					}
					pages_html+=this.getOtherPageHTML(i);
				}
			}else{
				if(this.currentPage>=this.totalPage-4){
					for(i=1;i<=2;i++){
						if(i == this.currentPage){
							pages_html+=current_page_html;
							continue;
						}
						pages_html+=this.getOtherPageHTML(i);
					}
					pages_html+=dot_html;
					for(i=this.totalPage-9;i<=this.totalPage;i++){
						if(i == this.currentPage){
							pages_html+=current_page_html;
							continue;
						}
						pages_html+=this.getOtherPageHTML(i);
					}
				}else{
					for(i=1;i<=2;i++){
						pages_html+=this.getOtherPageHTML(i);
					}
					if(this.currentPage-3 > 3){
						pages_html+=dot_html;
					}
					for(i = this.currentPage-3;i<=this.currentPage+4;i++){
						if(i<=2 || i>=this.totalPage-1) continue;
						if(i == this.currentPage){
							pages_html+=current_page_html;
							continue;
						}
						pages_html+=this.getOtherPageHTML(i);
					}
					if(i<this.totalPage-1){
						pages_html+=dot_html;
					}
					for(i=this.totalPage-1;i<=this.totalPage;i++){
						pages_html+=this.getOtherPageHTML(i);
					}
				}
			}
		}
		var html=prev_page_html+pages_html+next_page_html;
		//document.write(html);
		return html;
	}
	this.getOtherPageHTML=function (pageNum){
		return "<a href='javascript:void(0);' onclick='gotoPage(\""+pageNum+"\",\""+this.formId+"\");return false;'>"+pageNum+"</a>";
	}
	
	this.doPrint = function(id){
		document.getElementById(id).innerHTML=this.getPrintHTML();
	}
}

function gotoPage(pageNum,formId){
	var obj_form = document.getElementById(formId);
	document.getElementById("gotoPage").value = pageNum;
	obj_form.target="_self";
	obj_form.submit();
}

function getUnixTime()
			{  
				 var datum = new Date();
				 return datum.getTime();
			}